﻿using System.Reflection;
using System.Web.Mvc;
using Autofac;
using Autofac.Integration.Mvc;
using Owin;
using Quick.Common;
using PortalWeb.Core.IManager;
using PortalWeb.Service;
using PortalWeb.Dao;
using PortalWeb.Core.IDao;
using Quick.Common.Components;

namespace PortalWeb
{
    public partial class Startup
    {
        public void ConfigureAutofac(IAppBuilder app)
        {

            var builder = new ContainerBuilder();
            // STANDARD MVC SETUP:

            // Register Web API controller in executing assembly.
            builder.RegisterControllers(Assembly.GetExecutingAssembly());

            // OPTIONAL: Register model binders that require DI.
            builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
            builder.RegisterModelBinderProvider();

            //// Register the EntLib classes.
            //builder.RegisterEnterpriseLibrary();

            // OPTIONAL: Register web abstractions like HttpContextBase.
            builder.RegisterModule<AutofacWebTypesModule>();

            // OPTIONAL: Enable property injection in view pages.
            builder.RegisterSource(new ViewRegistrationSource());

            // OPTIONAL: Enable property injection into action filters.
            builder.RegisterFilterProvider();

            // Set the dependency resolver to be Autofac.
            // 解决依赖
            var container = builder.Build();
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            // OWIN MVC SETUP:
            // Register the Autofac middleware FIRST, then the Autofac MVC middleware.
            app.UseAutofacMiddleware(container);

            app.UseAutofacMvc();

            Quick.Common.Configuration.Instance.UseAutofac(container);
        }
    }
}